﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace HttpRequestDemo
{
    class Program
    {
        static string address = "https://localhost:44305/weatherforecast";

        static void Main(string[] args)
        {
            //Console.WriteLine(GetPrintingHouseGroup(-1));
            //Console.WriteLine(GetPrintingHouseGroup(-1, "1"));
            //Console.WriteLine(GetPrintingHouseGroup(1));
            //Console.WriteLine(GetPrintingHouseGroup(0));
            string result2 = GetPrintingHouseGroup(-1);
            string result = PostPrintingHouseGroup(-1);
            JArray jResult = (JArray)JsonConvert.DeserializeObject(result);
            foreach (JObject j in jResult)
            {
                string lastDate = j["lastDate"].ToString();
                Console.WriteLine(lastDate);
            }
        }

        /// <summary>
        /// get 印厂列表
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        static string GetPrintingHouseGroup(int state)
        {
            string result = HttpRequestHelper.HttpGetAsync($"{address}/company/List", $"?count=10000&page=0&state={state}").Result;
            return result;
        }

        /// <summary>
        /// get 印厂列表
        /// </summary>
        /// <param name="state"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static string GetPrintingHouseGroup(int state, string name)
        {
            string result = HttpRequestHelper.HttpGetAsync($"{address}/company/List", $"?count=10000&page=0&state=-1&name={name}").Result;
            return result;
        }

        /// <summary>
        /// post 印厂列表
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        static string PostPrintingHouseGroup(int state)
        {
            string para = $"?count=1000&page=1&state={state}";
            string result = HttpRequestHelper.HttpPostQueryAsync($"{address}/company/List", para).Result;
            return result;
        }
    }
}
